# -*- coding: utf-8 -*-
from __future__ import absolute_import

"""
缺失补漏脚本
"""
import glob
import pandas as pd


def insert_columns(month_statistics_dir):
    days = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
            11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
             21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31]
    inserts = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
               -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
    files = []
    files.extend(sorted(glob.glob("{}\\*本月云量统计结果.csv".format(month_statistics_dir))))
    for i in range(len(files)):
        data_matrix = pd.read_csv(files[i], engine='python')
        drop_matrix = data_matrix.drop(columns=['邮政编码', '县级单位'])
        cols = list(drop_matrix)
        cols = list(map(int, cols))
        loss_index = set(days).symmetric_difference(set(cols))
        for day in days:
            if day in loss_index:
                data_matrix.insert(loc=day+1, column=day, value=inserts)
        outfile = "{}.check_loss.csv".format(files[i][:-4])
        data_matrix.to_csv(outfile, encoding='gb2312') #编码解决输出中文乱码

    pass



if __name__ == "__main__":
    insert_columns("F:\\data\\modis_terra_cloud_mask\\20years\\Sep\\bin_cloud_mask")